package com.ruoyi.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.annotation.Excel.Type;
import com.ruoyi.common.annotation.Excels;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.xss.Xss;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author lzl
 */
@Data
public class SysUser extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @Excel(name = "用户序号", type = Type.EXPORT, cellType = ColumnType.NUMERIC, prompt = "用户编号")
    @TableId(value = "user_id", type = IdType.AUTO)
    private Long userId;

    /**
     * 部门ID
     */
    @Excel(name = "部门编号", type = Type.ALL)
    private Long deptId;

    /**
     * 部门父ID
     */
    @TableField(exist = false)
    private Long parentId;

    /**
     * 角色ID
     */
    @TableField(exist = false)
    private Long roleId;

    /**
     * 登录名称
     */
    @Excel(name = "登录名称", type = Type.IMPORT)
    private String loginName;

    /**
     * 用户名称
     */
    @Excel(name = "用户名称", type = Type.IMPORT)
    private String userName;

    /**
     * 用户类型
     */
    private String userType;

    /**
     * 用户邮箱
     */
    @Excel(name = "用户邮箱", type = Type.IMPORT)
    private String email;

    /**
     * 手机号码
     */
    @Excel(name = "手机号码", cellType = ColumnType.TEXT)
    private String phoneNumber;

    /**
     * 用户性别
     */
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 密码
     */
    private String password;

    /**
     * 盐加密
     */
    private String salt;

    /**
     * 账号状态（0正常 1停用）
     */
    @Excel(name = "账号状态", readConverterExp = "0=正常,1=停用")
    private String status;

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    private String delFlag;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP", type = Type.EXPORT)
    private String loginIp;

    /**
     * 最后登录时间
     */
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
    private Date loginDate;

    /**
     * 密码最后更新时间
     */
    private Date pwdUpdateDate;

    /**
     * 出生日期
     */
    @Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date birthDate;

    /**
     * 籍贯
     */
    @Excel(name = "籍贯")
    private String nativePlace;

    /**
     * 婚姻状况
     */
    @Excel(name = "婚姻状况")
    private Integer maritalStatus;

    /**
     * 身份证号码
     */
    @Excel(name = "身份证号码")
    private String idNumber;

    /**
     * 现居住地址
     */
    @Excel(name = "现居住地址")
    private String currentAddress;

    /**
     * 入职日期
     */
    @Excel(name = "入职日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date hireDate;

    /**
     * 入项日期
     */
    @Excel(name = "入项日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date projectStartDate;

    /**
     * 离项日期
     */
    @Excel(name = "离项日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date projectEndDate;

    /**
     * 办公地点
     */
    @Excel(name = "办公地点")
    private String officeLocation;

    /**
     * 甲方职务
     */
    @Excel(name = "甲方职务")
    private String partyAPosition;

    /**
     * 岗位
     */
    @Excel(name = "岗位")
    private String jobTitle;

    /**
     * 学历
     */
    @Excel(name = "学历")
    private String educationLevel;

    /**
     * 毕业院校
     */
    @Excel(name = "毕业院校")
    private String almaMater;

    /**
     * 入校时间
     */
    @Excel(name = "入校时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date admissionDate;

    /**
     * 毕业时间
     */
    @Excel(name = "毕业时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date graduationDate;

    /**
     * 专业
     */
    @Excel(name = "专业")
    private String major;

    /**
     * 紧急联系人姓名
     */
    @Excel(name = "紧急联系人姓名")
    private String emergencyContactName;

    /**
     * 紧急联系人关系
     */
    @Excel(name = "紧急联系人关系")
    private String emergencyContactRelationship;

    /**
     * 紧急联系人手机
     */
    @Excel(name = "紧急联系人手机")
    private String emergencyContactPhone;

    /**
     * 紧急联系人地址
     */
    @Excel(name = "紧急联系人地址")
    private String emergencyContactAddress;

    /**
     * 员工类型
     */
    @Excel(name = "员工类型")
    private String employeeType;

    /** 员工薪资 */
    @Excel(name = "员工薪资")
    private BigDecimal employeeSalary;

    /** 员工成本 */
    @Excel(name = "员工成本")
    private BigDecimal employeeCost;

    /** 雇佣类型(1-正式 2-试用 3-实习 4-劳务 5-外包) */
    @Excel(name = "雇佣类型")
    private Integer employmentType;

    /** 试用期月数 */
    @Excel(name = "试用期月数")
    private Integer probationMonths;

    /** 员工状态(1-在职 2-试用 3-离职 4-休假) */
    @Excel(name = "员工状态")
    private Integer employeeStatus;

    @Excel(name = "员工工号")
    private Integer employeeId;

    /**
     * 部门对象
     */
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    @TableField(exist = false)
    private SysDept dept;
    @TableField(exist = false)
    private List<SysRole> roles;

    /**
     * 角色组
     */
    @TableField(exist = false)
    private Long[] roleIds;

    /**
     * 岗位组
     */
    @TableField(exist = false)
    private Long[] postIds;

    public SysUser() {

    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    public Long getDeptId() {
        return deptId;
    }

    public void setDeptId(Long deptId) {
        this.deptId = deptId;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    @Xss(message = "登录账号不能包含脚本字符")
    @NotBlank(message = "登录账号不能为空")
    @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    @Xss(message = "用户昵称不能包含脚本字符")
    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @JsonIgnore
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @JsonIgnore
    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    public String getLoginIp() {
        return loginIp;
    }

    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    public Date getLoginDate() {
        return loginDate;
    }

    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }

    public Date getPwdUpdateDate() {
        return pwdUpdateDate;
    }

    public void setPwdUpdateDate(Date pwdUpdateDate) {
        this.pwdUpdateDate = pwdUpdateDate;
    }

    public SysDept getDept() {
        if (dept == null) {
            dept = new SysDept();
        }
        return dept;
    }
}
